package com.example.litemall.admin.api.service.impl;

import com.example.litemall.admin.api.domain.LitemallStorage;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.example.litemall.admin.api.mapper.LitemallStorageMapper;
import com.example.litemall.admin.api.service.LitemallStorageService;

import java.io.InputStream;
import java.util.UUID;

@Service
public class LitemallStorageServiceImpl implements LitemallStorageService{

    @Resource
    private LitemallStorageMapper litemallStorageMapper;

    @Override
    public LitemallStorage store(InputStream inputStream, long size, String contentType, String fileName) {
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
        String newName = UUID.randomUUID() + "." + suffix;


//        TencentStorage.store(inputStream, size, contentType, newName);

        String url = fileName;
        LitemallStorage storageInfo = new LitemallStorage();
        storageInfo.setName(fileName);
        storageInfo.setSize((int) size);
        storageInfo.setType(contentType);
        storageInfo.setKey(newName);
        storageInfo.setUrl(url);
//        litemallStorageService.add(storageInfo);

        return storageInfo;
    }
}
